package com.bilin.coin.activity;

import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bilin.coin.R;
import com.bilin.coin.bean.BiLinWallet;
import com.bilin.coin.bean.GoldBeanWrag;
import com.bilin.coin.bean.SeedDetailBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.tools.AbsHeadRecycleViewActivity;
import com.bilin.coin.tools.Geter;
import com.bilin.coin.utils.GsonUtil;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Route(path = "/auction/SeedDetailActivity")
public class SeedDetailActivity extends AbsHeadRecycleViewActivity<SeedDetailBean.RecordsBean> {


    private TextView tv_gold_num;
    private TextView tv_gold_num_f;

    @Override
    protected void initView() {
        super.initView();
        setTitle("种子明细");
        setMenu("种子规则");
        getWallet();
    }

    @Override
    public void setMenuOnClickListener() {
        super.setMenuOnClickListener();
        jumpArticle("3","种子规则");
    }

    @Override
    protected void convertItem(BaseViewHolder helper, SeedDetailBean.RecordsBean item) {
        helper.setText(R.id.tv_note,item.getNote());
        helper.setText(R.id.tv_time,item.getCreateTime());

        String latestUsable = item.getUsable();
        TextView tv_usable = helper.getView(R.id.tv_usable);
        if (Double.parseDouble(latestUsable) > 0) {
            tv_usable.setTextColor(getResources().getColor(R.color.colorBlue));
            helper.setText(R.id.tv_usable, "+"+latestUsable);
        } else {
            tv_usable.setTextColor(getResources().getColor(R.color.red_common2));

            helper.setText(R.id.tv_usable, ""+latestUsable);
        }

    }



    @Override
    protected int fillItemLayout() {
        return R.layout.item_gold;
    }

    @Override
    public int fillPageSize() {
        return 10;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public String fillUrl() {
        return "/api/bl-user-zz-log/list";
    }

    private void getWallet() {
        new Geter(this, false, true) {
            @Override
            protected String fillUrl() {
                return "/api/bl-wallet/getMoney";
            }

            @Override
            protected Map<String, String> fillParams() {
                return new HashMap<>();
            }

            @Override
            protected void disposeSuccess(String dataJson) {
                super.disposeSuccess(dataJson);
                BiLinWallet biLinWallet = GsonUtil.GsonToBean(dataJson, BiLinWallet.class);
                tv_gold_num.setText(biLinWallet.getZz());
            }
        };
    }

    @Override
    protected View fillHeadView() {
        View view = View.inflate(this,R.layout.head_seed_detail, null);
        tv_gold_num = view.findViewById(R.id.tv_gold_num);
        tv_gold_num_f = view.findViewById(R.id.tv_gold_num_f);
        return view;
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage", page + "");
        params.put("pageSize", pageSize + "");
        return params;
    }

    @Override
    public List<SeedDetailBean.RecordsBean> parseListDataAndFillTotal(String dataJson) {
        SeedDetailBean goldBeanWrag = GsonUtil.GsonToBean(dataJson, SeedDetailBean.class);
        totalCount = goldBeanWrag.getTotal();
        return goldBeanWrag.getRecords();
    }

    @Override
    protected void initData() {

    }


    @Override
    protected void refreshFragmentOrHead() {
        getWallet();
    }

}
